﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar.Extensions;

namespace PineLake.Drmwe.SystemConfig
{
    /// <summary>
    /// 系统配置类
    /// </summary>
    public class AppSettings
    {
        #region 数据库================================================================================
        /// <summary>
        /// 单库获取数据库连接字符串
        /// </summary>
        public static readonly string DbSqlConnection = AppSettingsHelper.GetContent("DbConnectionStrings", "SqlConnection");
        /// <summary>
        /// 单库获取数据库类型
        /// </summary>
        public static readonly string DbDbType = AppSettingsHelper.GetContent("DbConnectionStrings", "DbType");


        #region 多库

        public static readonly List<MultipleSqlConn> MultipleDbsConn = AppSettingsHelper.Get<MultipleSqlConn>("MultipleDbsConnection");

        #endregion

        #endregion

        #region Snow Flake (新版 雪花算法)
        /// <summary>
        /// WorkerId，机器码，最重要参数，无默认值，必须 全局唯一 取值范围(1-63)
        /// 特别提示：如果一台服务器部署多个独立服务，需要为每个服务指定不同的 WorkerId
        /// </summary>
        public static readonly ushort WorkerId = Convert.ToUInt16(AppSettingsHelper.GetContent("SnowFlakeSetting", "WorkerId").ToString());
        /// <summary>
        ///取值范围 [3, 21]（建议不小于4），决定每毫秒基础生成的ID个数。
        ///如果生成ID速度不超过5W/s，不用修改任何配置参数(默认 SeqBitLength=6).
        ///如果生成ID速度超过5W/s，低于50W，推荐修改：SeqBitLength=10
        ///如果生成ID速度超过50W/s，接近500W，推荐修改：SeqBitLength=12
        /// </summary>
        public static readonly byte SeqBitLength = Convert.ToByte(AppSettingsHelper.GetContent("SnowFlakeSetting", "SeqBitLength").ToString());

        //DataCenterId，数据中心ID（机房ID，默认0），请确保全局唯一。
        public static readonly uint DataCenterId = Convert.ToUInt32(AppSettingsHelper.GetContent("SnowFlakeSetting", "DataCenterId").ToString());

        //DataCenterIdBitLength，数据中心ID长度（默认0）
        public static readonly byte DataCenterIdBitLength = Convert.ToByte(AppSettingsHelper.GetContent("SnowFlakeSetting", "DataCenterIdBitLength").ToString());

        #endregion

        #region 跨域(Cors)跨域设置
        /// <summary>
        /// 跨域策略名称
        /// </summary>
        public static readonly string CorsPolicyName = AppSettingsHelper.GetContent("Cors", "PolicyName");
        /// <summary>
        /// 是否应用所有的IP，如设置为true，否则取消跨域限制(默认true)
        /// </summary>
        public static readonly bool CorsEnableAllIPs = AppSettingsHelper.GetContent("Cors", "EnableAllIPs").ObjToBool();

        /// <summary>
        /// IP 列表 "http://127.0.0.1:123,http://localhost:456"
        /// </summary>
        public static readonly string CorsIPs = AppSettingsHelper.GetContent("Cors", "IPs");

        #endregion

        #region ToKen 设置

        #region Jwt (验证 Token 方式)

        #region 授权(Authorization)
        /// <summary>
        /// Jwt Token 数字签名密钥(授权)
        /// </summary>
        public static readonly string AuthorKey = AppSettingsHelper.GetContent("JwtAuthorization", "AuthKey");
        /// <summary>
        /// 颁发Token者(授权)
        /// </summary>
        public static readonly string AuthorIssuer = AppSettingsHelper.GetContent("JwtAuthorization", "Issuer");
        /// <summary>
        /// 接收Token者(授权)
        /// </summary>
        public static readonly string AuthorAudience = AppSettingsHelper.GetContent("JwtAuthorization", "Audience");
        /// <summary>
        /// 过期时间(整数 天)(授权)
        /// </summary>
        public static readonly string AuthorExpires = AppSettingsHelper.GetContent("JwtAuthorization", "Expires");

        #endregion

        #region 鉴权(Authentication)

        /// <summary>
        /// Jwt Token 数字签名密钥(鉴权)
        /// </summary>
        public static readonly string AuthenKey = AppSettingsHelper.GetContent("JwtAuthentication", "AuthenKey");

        /// <summary>
        /// 颁发Token者(鉴权)
        /// </summary>
        public static readonly string AuthenIssuer = AppSettingsHelper.GetContent("JwtAuthentication", "Issuer");
        /// <summary>
        /// 接收Token者(鉴权)
        /// </summary>
        public static readonly string AuthenAudience = AppSettingsHelper.GetContent("JwtAuthentication", "Audience");
        /// <summary>
        /// ClockSkew默认值为5分钟，它是一个缓冲期，例如Token设置有效期为30分钟 过期时间为35分钟(鉴权)
        /// </summary>
        public static readonly string AuthenClockSkew = AppSettingsHelper.GetContent("JwtAuthentication", "ClockSkew");

        #endregion

        #endregion

        #endregion

        #region 设置 加密算法 密钥
        #region DES
        /// <summary>
        /// DESKey 地址
        /// </summary>
        public static readonly string DESKey = AppSettingsHelper.GetContent("EncryptSetting", "DESKey");

        #endregion

        #region AES
        /// <summary>
        /// AES 密钥
        /// </summary>
        public static readonly string AESKey = AppSettingsHelper.GetContent("EncryptSetting", "AESKey");
        /// <summary>
        /// AES IV
        /// </summary>
        public static readonly string AES_IV = AppSettingsHelper.GetContent("EncryptSetting", "AES_IV");

        #endregion

        #endregion

        #region 文件系统

        /// <summary>
        /// 私有根文件夹路径
        /// </summary>
        public static readonly string PrivateMasterFolderPath = AppSettingsHelper.GetContent("FileSystem", "PrivateMasterFolderPath");

        #endregion
    }
}
